package pers.course.week9;

import java.util.*;

public class PresidentOffice {
    private static int[][] directions = {{-1, 0, 1, 0}, {0, 1, 0, -1}};
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        boolean[] mark = new boolean[26];
        char[][] s = new char[100][100];
        int n = in.nextInt();
        int m = in.nextInt();
        int sum = 0;
        String pre = in.next();
        String[] str = new String[n];
        char president = pre.charAt(0);
        for (int i = 0; i < n; i++) {
            str[i] = in.next();
            s[i] = str[i].toCharArray();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (s[i][j] == president)
                    for (int k = 0, x, y; k < 4; k++) {
                        x = i + directions[0][k];
                        y = j + directions[1][k];
                        if (x >= 0 && x < n &&
                                y >= 0 && y < m &&
                                s[x][y] != '.' &&
                                s[x][y] != president &&
                                !mark[s[x][y] - 'A'])
                            mark[s[x][y] - 'A'] = true;
                    }
            }
        }
        for (int i = 0; i < 26; i++) {
            if (mark[i])
                sum++;
        }
        System.out.println(sum);
    }
}
